package com.gengzp.mq.client.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.http.HttpClient;
import java.time.Duration;

import static com.gengzp.mq.client.constants.MqTimeoutConstants.GET_MESSAGE_CONNECT_TIMEOUT;

/**
 * @ClassName MqHttpClientConfig
 * @Description mq 客户端内置 httpClient 配置类
 * @Author gengzp
 * @Date 2025/9/24 17:57
 */
@Configuration
public class MqHttpClientConfig {

    /**
     * rpc框架内置 Java HttpClient
     */
    @Bean
    public HttpClient mqHttpClient() {
        return HttpClient.newBuilder()
                // 连接超时设置
                .connectTimeout(Duration.ofSeconds(GET_MESSAGE_CONNECT_TIMEOUT))
                // 启用HTTP/2支持
                .version(HttpClient.Version.HTTP_2)
                // 跟随重定向
                .followRedirects(HttpClient.Redirect.NORMAL)
                .build();
    }

}
